//
//  FKCouponListCell.m
//  HappyTest
//
//  Created by Macbook Pro on 2019/1/9.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKCouponListCell.h"
#import "FKCoupon.h"

#define kCanGetColor fkColor(246, 116, 30)

@interface FKCouponListCell ()

@property (nonatomic, weak) UIImageView *bgView;
@property (nonatomic, weak) UILabel *priceLabel;
@property (nonatomic, weak) UILabel *conditionLabel;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *timeLabel;
@property (nonatomic, weak) UILabel *statusLabel;

@end

@implementation FKCouponListCell


- (void)setupSubviews
{
    [super setupSubviews];
    self.backgroundColor = [UIColor clearColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coupon_bg"]];
    [self.contentView addSubview:bgView];
    self.bgView = bgView;
    bgView.highlightedImage = [UIImage imageNamed:@"coupon_bg_high"];
    
    UILabel *priceLabel = [UILabel fk_labelWithFont:fk_adjustFont(23) textColor:fkMainColor];
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    UILabel *conditionLabel = [UILabel fk_labelWithFont:fk_adjustFont(11) textColor:fkColor333333 textAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:conditionLabel];
    self.conditionLabel = conditionLabel;
    conditionLabel.numberOfLines = 2;
    
    UIView *separator = [[UIView alloc] init];
    [self.contentView addSubview:separator];
    separator.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    UILabel *titleLabel = [UILabel fk_labelWithFont:fk_adjustFont(13) textColor:fkColor333333];
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UILabel *timeLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor999999];
    [self.contentView addSubview:timeLabel];
    self.timeLabel = timeLabel;
    
    UILabel *statusLabel = [UILabel fk_labelWithFont:fk_adjustFont(16) textColor:[UIColor whiteColor] textAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:statusLabel];
    self.statusLabel = statusLabel;
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(fk_adjustW(10));
        make.right.offset(fk_adjustW(-10));
        make.top.bottom.offset(0);
    }];
    [separator mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(0.8);
        make.height.offset(fk_adjustW(60));
        make.centerY.offset(0);
        make.left.equalTo(bgView).offset(fk_adjustW(88));
    }];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(fk_adjustW(80));
        make.left.equalTo(bgView).offset(6);
        make.bottom.equalTo(bgView.mas_centerY).offset(-4);
    }];
    [conditionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.equalTo(priceLabel);
        make.top.equalTo(bgView.mas_centerY).offset(4);
    }];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(separator.mas_right).offset(fk_adjustW(12));
        make.centerY.equalTo(priceLabel);
    }];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.centerY.equalTo(conditionLabel);
    }];
    [statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(fk_adjustW(89));
        make.centerY.offset(0);
        make.right.equalTo(bgView);
    }];
}

- (void)setData:(id)data
{
    [super setData:data];
    
    if ([data isKindOfClass:[FKCoupon class]]) {
        FKCoupon *coupon = data;
        
        self.bgView.highlighted = coupon.high;
        self.priceLabel.attributedText = coupon.priceStr;
        self.conditionLabel.text = coupon.conditionStr;
        self.titleLabel.text = coupon.title;
        self.timeLabel.text = fkFORMAT(@"%@-%@", coupon.startTime, coupon.endTime);
        self.statusLabel.text = coupon.statusName;
    }
}


@end
